<?php

namespace app\app\controller\user;

use app\app\controller\AppBase;
use app\app\validate\user\LoginValidate;

class Login extends AppBase
{


    protected $noNeedLogin = ['logins'];

    /**
     * Notes: 登录
     * User: AerYYY
     * Date: 7/2/25
     */
    public function logins()
    {
        $params = request()->post();
        $validate = new LoginValidate();
        if (!$validate->scene('logins')->check($params)) {
            $this->error($validate->getError());
        }
        $ret = $this->login($params['username'], $params['password']);
        if ($ret) {
            $data = ['userinfo' => $this->getAdminInfo()];
            $this->success(__('Logged in successful'), $data);
        } else {
            $this->error($this->getError());
        }
        $this->success('ok');
    }


    /**
     * 退出登录
     * @ApiMethod (POST)
     */
    public function logouts()
    {
        if (!$this->request->isPost()) {
            $this->error(__('Invalid parameters'));
        }
        $this->logout();
        $this->success(__('Logout successful'));
    }


}